package com.boyadegroot.divelog.ui.diver;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.boyadegroot.divelog.R;
import com.boyadegroot.divelog.models.Diver;
import com.boyadegroot.divelog.ui.diver.tabs.DiverCerts;
import com.boyadegroot.divelog.ui.diver.tabs.DiverDives;
import com.boyadegroot.divelog.ui.diver.tabs.DiverLocations;
import com.boyadegroot.divelog.ui.diver.tabs.DiverStats;

public class DiverAdapter extends FragmentStatePagerAdapter {

    private static final String TAG = DiverAdapter.class.getName();

    public static final int NUM_PAGES = 4;
    public static final int PAGE_DIVES = 0;
    public static final int PAGE_LOCATIONS = 1;
    public static final int PAGE_STATS = 2;
    public static final int PAGE_CERTS = 3;

    private final Context mContext;

    private final Diver mDiver;

    public DiverAdapter(FragmentManager fm, Diver diver, Context context) {
        super(fm);
        // Log.v(TAG, "DiverAdapter(FragmentManager fm, Diver diver, Context context)");
        mDiver = diver;
        mContext = context;
    }

    @Override
    public Fragment getItem(int position) {
        // Log.v(TAG, "getItem(position = " + position + ")");
        switch (position) {
            case PAGE_DIVES:
                // Log.v(TAG, "return DiverDives");
                return DiverDives.newInstance(mDiver);
            case PAGE_LOCATIONS:
                // Log.v(TAG, "return DiverLocationsMap");
                return DiverLocations.newInstance(mDiver);
            case PAGE_STATS:
                // Log.v(TAG, "return DiverStats");
                return DiverStats.newInstance(mDiver);
            case PAGE_CERTS:
                // Log.v(TAG, "return DiverDives");
                return DiverCerts.newInstance(mDiver);
        }
        return null;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        // Log.v(TAG, "getPageTitle(position = " + position + ")");
        switch (position) {
            case PAGE_DIVES:
                return mContext.getString(R.string.title_dives);
            case PAGE_LOCATIONS:
                return mContext.getString(R.string.title_divelocations);
            case PAGE_STATS:
                return mContext.getString(R.string.title_stats);
            case PAGE_CERTS:
                return mContext.getString(R.string.title_certs);
        }
        return null;
    }

    @Override
    public int getCount() {
        // Log.v(TAG, "getCount()");
        return NUM_PAGES;
    }

    @Override
    public int getItemPosition(Object item) {
        // Log.v(TAG, "getItemPosition(Object item)");
        return POSITION_NONE;
    }
}
